package de.hauschild.dbc4j.engine;

import java.util.HashMap;
import java.util.Map;

import de.hauschild.dbc4j.annotation.PostCondition;
import de.hauschild.dbc4j.annotation.PreCondition;
import de.hauschild.dbc4j.engine.groovy.GroovyContractEngine;

/**
 * Utility class managing all registered {@link ContractEngine ContractEngines}.
 * 
 * @since 1.0.0
 * @author Klaus Hauschild
 */
public class ContractEngineUtils {

  private static Map<String, ContractEngine> contractEngines = new HashMap<String, ContractEngine>();

  static {
    contractEngines.put(GroovyContractEngine.ENGINE_NAME, new GroovyContractEngine());
  }

  /**
   * Gets the contract engine.
   * 
   * @param postCondition
   *          the postcondition
   * @return the contract engine
   */
  public static ContractEngine getContractEngine(final PostCondition postCondition) {
    return getContractEngine(postCondition.engine());
  }

  /**
   * Gets the contract engine.
   * 
   * @param preCondition
   *          the precondition
   * @return the contract engine
   */
  public static ContractEngine getContractEngine(final PreCondition preCondition) {
    return getContractEngine(preCondition.engine());
  }

  /**
   * Gets the contract engine.
   * 
   * @param name
   *          the name
   * @return the contract engine
   */
  private static ContractEngine getContractEngine(final String name) {
    return contractEngines.get(name);
  }

  /**
   * Instantiates a new {@link ContractEngineUtils}.
   */
  private ContractEngineUtils() {
  }
}
